//
//  GSBottomADView.m
//  GameSky
//
//  Created by lanou on 16/1/16.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSBottomADView.h"

#define kMargin 10

@implementation GSBottomADView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        self.coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(kMargin, kMargin, kWidth - kMargin * 2, 150)];
        [self addSubview:self.coverImage];
        
        UIImageView *promImage = [[UIImageView alloc] initWithFrame:CGRectMake(kMargin, self.coverImage.bottom + 5, 31, 17)];
        promImage.image = [UIImage imageNamed:@"common_Badge_TuiGuang_31x17_UIMode_Day"];
        [self addSubview:promImage];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(promImage.right + kMargin, promImage.top, kWidth - kMargin * 3 - promImage.width, promImage.height)];
        self.titleLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:self.titleLabel];
    }
    return self;
}

- (void)setModel:(GSNewsADModel *)model {
    _model = model;
    [self.coverImage sd_setImageWithURL:[NSURL URLWithString:model.icon] placeholderImage:kPHImage];
    self.titleLabel.text = model.title;
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_model.link]];
}

@end
